home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / utilities / shells / sksh / scr_source / path.s < prev    next >
Text File  |  1995-03-17  |  2KB  |  68 lines

  1. #!c:sksh
  2.  
  3. #*************************************************************************
  4. # The following function implements the SKsh path command
  5. #*************************************************************************
  6.  
  7.     local _comp _deltap _o_add _o_cd _o_man _o_path _dir _var
  8.  
  9.     _o_add=''; _o_cd=''; _o_man=''; _o_path='T'
  10.  
  11.     _deltap="$PATH"; _var='PATH'
  12.  
  13.     # --- parse the command line switches ------------------------------------
  14.  
  15.     while [ $(expr substr "$1" 1 1) = '-' ]
  16.     do
  17.        case "$1" in
  18.           -add ) _o_add='T'; shift
  19.                  ;;
  20.           -cd  ) _o_cd='T'; _o_path=''; _deltap="$CDPATH"; _var='CDPATH'
  21.                  shift
  22.                  ;;
  23.           -path) shift;
  24.                  ;;
  25.           -man ) _o_man='T'; _o_path=''; _deltap="$MANPATH"; _var='MANPATH'
  26.                  shift
  27.                  ;;
  28.           *    ) echo 'Usage:' $(basename $0) \
  29.                       '[ -cd | -path | -man ] [ -add ] dir1,dir2,...'
  30.                  shift
  31.                  return 1
  32.                  ;;
  33.        esac
  34.     done
  35.  
  36.     # --- if no directories were listed, just echo the right path ------------
  37.  
  38.     [ "$#" -eq 0 ] && echo "$_deltap" && return
  39.  
  40.     # --- if the path is to be reset, use the right initial value ------------
  41.  
  42.     if [ -z "$_o_add" ]
  43.     then
  44.        _deltap=''
  45.        [ -n "$_o_path" ] && _deltap='skshbin:,skshscr:,.,c:'
  46.        [ -n "$_o_man" ]  && _deltap='MAN:,MAN:SKsh'
  47.     fi
  48.  
  49.     # --- add the compontents the user gave us to the path -------------------
  50.  
  51.     for _comp in $* do                   # for each argument, do
  52.         while [ -n "$_comp" ]
  53.         do
  54.            _dir  = $(car "$_comp" ',')   # first component of path
  55.            _comp = $(cdr "$_comp" ',')   # rest of path
  56.            if [ $( expr index "$_deltap," "$_dir," ) -eq 0 ]
  57.            then
  58.               if [ -z "$_deltap" ] then _deltap="$_dir"
  59.               else _deltap = "$_deltap,$_dir"; fi
  60.            fi
  61.         done
  62.     done
  63.  
  64.     # --- export the path again to the right variable ------------------------
  65.  
  66.     "$_var"="$_deltap"     # $_var = PATH, CDPATH, or MANPATH
  67.     export -l "$_var"
  68.